import { useMemo } from 'react';
import usePlanStore from '../store/planStore';
import { getToday } from '../utils/dateUtils';

/**
 * 计划相关的自定义 Hook
 */
export const usePlans = () => {
  const {
    plans,
    addPlan,
    updatePlan,
    deletePlan,
    togglePlanStatus,
    getPlansByDate,
    getPlansByType,
    getPlansByStatus,
  } = usePlanStore();

  // 获取今日计划
  const todayPlans = useMemo(() => {
    return getPlansByDate(getToday());
  }, [plans]);

  // 获取待完成计划
  const pendingPlans = useMemo(() => {
    return getPlansByStatus('pending');
  }, [plans]);

  // 获取已完成计划
  const completedPlans = useMemo(() => {
    return getPlansByStatus('completed');
  }, [plans]);

  // 获取日计划
  const dailyPlans = useMemo(() => {
    return getPlansByType('daily');
  }, [plans]);

  return {
    plans,
    todayPlans,
    pendingPlans,
    completedPlans,
    dailyPlans,
    addPlan,
    updatePlan,
    deletePlan,
    togglePlanStatus,
    getPlansByDate,
  };
};

